'use strict';
const Controller = require('egg').Controller;

class AdminController extends Controller{
	async index(){
		const { ctx } = this;
		const user = await this.app.mysql.get('users', { id: 1 });
		console.log(user)
		ctx.body = 'index';
	}
	async list(){
		const { ctx } = this;
		const list = await ctx.service.admin.list();
		ctx.body = list;
	}
	async edit(data){
		const { ctx } = this;
    const isedit =  await ctx.service.admin.edit(data);
		ctx.body = { message:'编辑成功' };
	}
	async add(data){
		const { ctx } = this;
		for (const key in ctx.request.body) {
			if(!ctx.request.body[key]){
        ctx.body = `${key}参数不能为空`;
				return
			}
		}
		const isadd =  await ctx.service.admin.add(ctx.request.body);
		
	}
	async delete(){
		const { ctx } = this;
		const isadd =  await ctx.service.admin.delete(id);
		ctx.body = 'delate';
	}
}

module.exports = AdminController